package com.bwie.parkdemo.mvvm.model.entity;

import com.bwie.lib_core.base.BaseEntity;
import com.google.gson.Gson;
import org.json.JSONArray;
import org.json.JSONException;
import java.util.ArrayList;
import java.util.List;

/**
 * 全部车位实体
 * {
 *   "msg": "申请成功",
 *   "values": "[{\"parkUser\":0,\"parkTime\":\"0\",
 *   \"parkName\":\"杨东文专属\",
 *   \"parkEnd\":\"0\",\"parkId\":47,\"parkStart\":\"0\"}]",
 *   "statuesCode": "200"
 * }
 * */
public class ParkingAllEntity extends BaseEntity {

    public String values;
    private ArrayList<Object>parkinges;

    public ArrayList<Object> getParkinges() {
        if (parkinges == null){
            parkinges = new ArrayList<>();
            if (values.equals("[]"))
                return parkinges;
            try {
                JSONArray jay = new JSONArray(values);
                for (int i = 0;i < jay.length();i ++){
                    Values v = new Gson().fromJson(jay.getJSONObject(i).toString(),Values.class);
                    Object ob = v;
                    parkinges.add(ob);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return parkinges;
    }

    public static class Values{
        public int parkUser;//当车位空余->没有被选中；没有处于待申请状态->为0
        //被使用或被申请时返回对应用户id
        public int parkId;
        public String parkTime;
        public String parkName;
        public String parkEnd;
        public String parkStart;
        public boolean leftFlag = false;
    }
}
